package util;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodeFilter extends AbstractFilter{
	
	private String charset="UTF-8";
	@Override
	public void init(FilterConfig config) throws ServletException {
		String encode=config.getInitParameter(charset);
		if(encode!=null&!"".equals(encode)){
			charset=encode;
		}
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		
		req.setCharacterEncoding(charset);
		resp.setCharacterEncoding(charset);
		chain.doFilter(req, resp);
	}
	
}
